#include "main.h"
#include "GUI.h"
#include "Global.h"
#include "CLevel.h"

void SetGUIColors(GUI_COLORS* _guicolors){
	_guicolors->BG=CLR_NULL;
	_guicolors->Border=CLR_NULL;
	_guicolors->Text=CLR_NULL;
	_guicolors->MouseDown=CLR_NULL;
	_guicolors->MouseOver=CLR_NULL;
}
GUI_COLORS* SetGUIColors(){
	GUI_COLORS* _guicolors = new GUI_COLORS();
	_guicolors->BG=CLR_NULL;
	_guicolors->Border=CLR_NULL;
	_guicolors->Text=CLR_NULL;
	_guicolors->MouseDown=CLR_NULL;
	_guicolors->MouseOver=CLR_NULL;
	return _guicolors;
}
GUI_SPRITES* SetGUISprites(CSprite* _bg, CSprite* _border, CSprite* _mouseover, CSprite* _mousedown, CSprite* _cursor){
	GUI_SPRITES* _guisprites = new GUI_SPRITES();
	_guisprites->BG=_bg;
	_guisprites->Border=_border;
	_guisprites->g_pCursor=_cursor;
	_guisprites->MouseDown=_mousedown;
	_guisprites->MouseOver=_mouseover;
	return _guisprites;
};
GUI_COLORS* SetGUIColors(D3DCOLOR _bg, D3DCOLOR _border, D3DCOLOR _mouseover, D3DCOLOR _mousedown, D3DCOLOR _text){
	GUI_COLORS* _guicolors = new GUI_COLORS();
	_guicolors->BG=_bg;
	_guicolors->Border=_border;
	_guicolors->Text=_text;
	_guicolors->MouseDown=_mousedown;
	_guicolors->MouseOver=_mouseover;
	return _guicolors;
};

//Vector2 V(float x, float y){
	//return Vector2(x, y);
//}

void SortEntList(CEntityList* list){
	Node<CEntity>* EntityIt = NULL;
	for (int i = 0; i < list->getSize()/2; i++ ) {
		EntityIt = list->first();
		for (int j = 0; j+1 < list->getSize(); j += 2){
			if (EntityIt->object->getDepth() > EntityIt->next->object->getDepth()) {
				CEntity* T = EntityIt->object;
				EntityIt->object = EntityIt->next->object;
				EntityIt->next->object = T;
			}
			EntityIt = EntityIt->next->next;
		}
		EntityIt = list->first()->next;
		for (int j = 1; j+1 < list->getSize(); j += 2){
			if (EntityIt->object->getDepth() > EntityIt->next->object->getDepth()) {
				CEntity* T = EntityIt->object;
				EntityIt->object = EntityIt->next->object;
				EntityIt->next->object = T;
			}
			EntityIt = EntityIt->next->next;
		}
	}
}

void SortGUIList(LinkedList<CGUIBase>* list, LinkedList<CGUIBase>* drawlist){
	Node<CGUIBase>* EntityIt = NULL;
	Node<CGUIBase>* LastEntityIt = NULL;
	CGUIBase* T=NULL;
	list->clear();
	list->Init();
	EntityIt= drawlist->first();
		while(EntityIt!=NULL){
			list->add(EntityIt->object);
			EntityIt = EntityIt -> next;
		}
	for (int i = 0; i < drawlist->getSize()/2; i++ ) {
		EntityIt = drawlist->first();
		LastEntityIt = list->first();
		
		for (int j = 0; j+1 < drawlist->getSize(); j += 2){
			if (EntityIt->object->getDepth() > EntityIt->next->object->getDepth()) {
				T = EntityIt->object;
				EntityIt->object = EntityIt->next->object;
				EntityIt->next->object = T;
			}else{
				T = LastEntityIt->object;
				LastEntityIt->object = LastEntityIt->next->object;
				LastEntityIt->next->object = T;
			}
			EntityIt = EntityIt->next->next;
			LastEntityIt = LastEntityIt->next->next;
		}
		EntityIt = drawlist->first()->next;
		LastEntityIt = list->first()->next;
		for (int j = 1; j+1 < drawlist->getSize(); j += 2){
			if (EntityIt->object->getDepth() > EntityIt->next->object->getDepth()) {
				T = EntityIt->object;
				EntityIt->object = EntityIt->next->object;
				EntityIt->next->object = T;
			}else{
				T = LastEntityIt->object;
				LastEntityIt->object = LastEntityIt->next->object;
				LastEntityIt->next->object = T;
			}
			EntityIt = EntityIt->next->next;
			LastEntityIt = LastEntityIt->next->next;
		}
	}
}

void SetBlendType(const short BLEND_TYPE){
	g_BlendType=BLEND_TYPE;
}

int toInt(string _line){
	istringstream buffer(_line);
	int value;
	buffer >> value;
	return value;
}
std::string toStr(int _value){
    std::ostringstream outStream;

    outStream << _value;
	return outStream.str();
}
std::string toStr(long long _value){
    std::ostringstream outStream;

    outStream << _value;
	return outStream.str();
}
std::string toStr(float _value){
    std::ostringstream outStream;

    outStream << _value;
	return outStream.str();
}